using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using yq.IBase;
using yq.Dictionary;
using yq.Basis;
using yq.Model.Logic;
using System.Collections;
using Db;
using System.Data.Common;

namespace yq.Model.Base
{
    ///<summary>
    /// User_Account - 用户表 - 对象基础类
    /// </summary>
    ///<typeparam name="T"></typeparam>
    public abstract class IUserAccount<T> : ModelBase<UserAccount> where T : UserAccount, new()
    {
        /// <summary>
        /// 写入主键值
        /// </summary>
        /// <param name="Id">主键</param>
        protected internal override void SetKeyValue(dynamic Id)
        {
            this.UserId = Id;
        }

        /// <summary>
        /// 获取主键值
        /// </summary>
        /// <returns></returns>
        protected internal override dynamic GetKeyValue()
        {
            return UserId;
        }

        /// <summary>
        /// 为本对象赋值
        /// </summary>
        /// <param name="dy"></param>
        public override void SetValue(dynamic dy)
        {
            this.UserId = dy.UserId;
            this.NickName = dy.NickName;
            this.State = dy.State;
            this.CreateTtime = dy.CreateTtime;
            this.PurviewEnum = dy.PurviewEnum;
            this.Version = dy.Version;
        }

        #region 定义属性


        /// <summary>
        /// 用户ID
        /// </summary>
        private String _UserId = "";

        /// <summary>
        /// 用户ID
        /// </summary>
        public String UserId
        {
            get
            {
                return (this._UserId);
            }

            set
            {
                _UserId = value;
            }
        }


        /// <summary>
        /// 昵称
        /// </summary>
        private String _NickName = "";

        /// <summary>
        /// 昵称
        /// </summary>
        public String NickName
        {
            get
            {
                return (this._NickName);
            }

            set
            {
                _NickName = value;
            }
        }


        /// <summary>
        /// 状态
        /// </summary>
        private int _State = -1;

        /// <summary>
        /// 状态
        /// </summary>
        public yq.Enums.UserAccount.State State
        {
            get
            {
                return (yq.Enums.UserAccount.State)this._State;
            }

            set
            {
                _State = value.GetHashCode();
            }
        }


        /// <summary>
        /// 注册时间
        /// </summary>
        private DateTime _CreateTtime = DateTime.MinValue;

        /// <summary>
        /// 注册时间
        /// </summary>
        public DateTime CreateTtime
        {
            get
            {
                return (this._CreateTtime);
            }

            set
            {
                _CreateTtime = value;
            }
        }


        /// <summary>
        /// 权限组ID
        /// </summary>
        private int _PurviewEnum = -1;

        /// <summary>
        /// 权限组ID
        /// </summary>
        public yq.Enums.UserAccount.PurviewEnum PurviewEnum
        {
            get
            {
                return (yq.Enums.UserAccount.PurviewEnum)this._PurviewEnum;
            }

            set
            {
                _PurviewEnum = value.GetHashCode();
            }
        }


        #endregion 定义属性

        protected internal override void SetValue(UserAccount info, DataRow row)
        {
            if (row == null)
            {
                info.IsLoad = false;
            }
            else
            {
                info.IsLoad = true;

                if (row["UserId"] != DBNull.Value)
                {
                    info.UserId = row["UserId"].ToString();
                }


                if (row["NickName"] != DBNull.Value)
                {
                    info.NickName = row["NickName"].ToString();
                }


                if (row["State"] != DBNull.Value)
                {
                    info.State = (yq.Enums.UserAccount.State)(row["State"]);
                }


                if (row["CreateTtime"] != DBNull.Value)
                {
                    info.CreateTtime = Convert.ToDateTime(row["CreateTtime"]);
                }


                if (row["PurviewEnum"] != DBNull.Value)
                {
                    info.PurviewEnum = (yq.Enums.UserAccount.PurviewEnum)(row["PurviewEnum"]);
                }


                if (row["Version"] != DBNull.Value)
                {
                    info.Version = row["Version"].ToString();
                }

            }

        }

        protected internal override void GetDbParameters(DbCommand comm, UserAccount info, DbHelper cn)
        {

            cn.AddInParameter(comm, "@UserId", DbType.String, ParameterTool.GetObj(info._UserId));


            cn.AddInParameter(comm, "@NickName", DbType.String, ParameterTool.GetObj(info._NickName));


            cn.AddInParameter(comm, "@State", DbType.Int32, ParameterTool.GetObj(info._State));


            cn.AddInParameter(comm, "@CreateTtime", DbType.DateTime, ParameterTool.GetObj(info._CreateTtime));


            cn.AddInParameter(comm, "@PurviewEnum", DbType.Int32, ParameterTool.GetObj(info._PurviewEnum));


            cn.AddInParameter(comm, "@Version", DbType.String, Guid.NewGuid().ToString());


            cn.AddInParameter(comm, "@_versionOdl", DbType.String, info._Version);

        }

    }
}